package com.xingchen.feima.star.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xingchen.feima.common.utils.R;
import com.xingchen.feima.star.entity.NonLoadingTimeWindow;
import com.xingchen.feima.star.service.NonLoadingTimeWindowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 不可装料时间窗表 前端控制器
 * </p>
 *
 * @author yangxc
 * @since 2025-02-10
 */
@Api(tags = "不可装料时间窗管理")
@RestController
@RequestMapping("/star/nonLoadingTimeWindow")
public class NonLoadingTimeWindowController {

    @Autowired
    private NonLoadingTimeWindowService nonLoadingTimeWindowService;


    @ApiOperation(value = "根据机组id获取不可装料时间窗列表")
    @GetMapping("/getNonLoadingTimeWindowListByUnitId/{id}")
    public R getNonLoadingTimeWindowListByUnitId(
            @ApiParam(name = "id", value = "机组id", required = true)
            @PathVariable Long id){
        List<NonLoadingTimeWindow> nonLoadingTimeWindowListByUnitId = nonLoadingTimeWindowService.list(new QueryWrapper<NonLoadingTimeWindow>().eq("unit_id", id));
        return R.ok().data("items", nonLoadingTimeWindowListByUnitId);
    }

    @ApiOperation(value = "新增不可装料时间窗")
    @PostMapping("")
    public R add(
            @ApiParam(name = "nonLoadingTimeWindow", value = "不可装料时间窗对象", required = true)
            @RequestBody NonLoadingTimeWindow nonLoadingTimeWindow){

        nonLoadingTimeWindowService.save(nonLoadingTimeWindow);
        return R.ok().message("添加成功");
    }

    @ApiOperation(value = "根据id查询不可装料时间窗")
    @GetMapping("/{id}")
    public R getById(
            @ApiParam(name = "id", value = "不可装料时间窗id", required = true)
            @PathVariable Long id){

        NonLoadingTimeWindow nonLoadingTimeWindow = nonLoadingTimeWindowService.getById(id);
        return R.ok().data("items", nonLoadingTimeWindow);
    }

    @ApiOperation(value = "根据id修改不可装料时间窗")
    @PutMapping("")
    public R updateById(
            @ApiParam(name = "nonLoadingTimeWindow", value = "不可装料时间窗对象", required = true)
            @RequestBody NonLoadingTimeWindow nonLoadingTimeWindow){

        nonLoadingTimeWindowService.updateById(nonLoadingTimeWindow);
        return R.ok().message("修改成功");
    }

    @ApiOperation(value = "根据id删除不可装料时间窗")
    @DeleteMapping("/{id}")
    public R removeById(
            @ApiParam(name = "id", value = "不可装料时间窗id", required = true)
            @PathVariable Long id){

        nonLoadingTimeWindowService.removeById(id);
        return R.ok().message("删除成功");
    }

    @ApiOperation("根据id列表批量删除不可装料时间窗")
    @DeleteMapping("/batchRemove")
    public R batchRemove(
            @ApiParam(name = "idList", value = "id列表", required = true)
            @RequestBody List<Long> idList) {

        nonLoadingTimeWindowService.removeByIds(idList);
        return R.ok().message("批量删除成功");
    }
}

